package spoon.sbobet.task;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import spoon.sbobet.domain.GameLink;
import spoon.sbobet.service.SbobetService;


@Component
public class SbobetFootballTask {

	Logger log = LoggerFactory.getLogger(SbobetFootballTask.class);

	@Autowired
	@Qualifier("sbobetFootballService")
	private SbobetService footballService;

	private List<GameLink> linkList = new ArrayList<GameLink>();

	/**
	 * 축구 경기를 가져온다.
	 */
	@Scheduled(fixedDelayString = "${sbobet.football.delay}")
	public void taskGame() {
		
		int linkSize = this.linkList.size();
		
		if (linkSize == 0) {
			taskLink();
			return;
		}
		
		GameLink link = this.linkList.remove(0);
		footballService.getGame(link);
		
	}
	
	/**
	 * 축구 리그를 가져온다.
	 */
	public void taskLink() {
		linkList.addAll(footballService.getLink());
	}
}
